<?php
namespace Home\Controller;
class ProductCommentController extends BaseController {
      public function comment(){
          //获取订单id
         $oid=I('get.oid');
         $re= M('order')->where(array('oid'=>$oid))->find();
         $val=json_decode($re['content'],true);
        //按照订单号进行评论  
         $id=I('get.id');
         foreach ($val as $k=>$v){
           if($v['id']==$id){
              $good=$val[$k];      
           }  
         }
        
         $time=time();
         $re=M('goods_attr')->where(array('goods_id'=>$good['id']))->select();
         //得到属性ID去属性表 查询属性名
        $first= M('attr')->where(array('id'=>$re[0]['attr_id']))->find();
        $second=M('attr')->where(array('id'=>$re[1]['attr_id']))->find();
        $third= M('attr')->where(array('id'=>$re[2]['attr_id']))->find();
        $this->assign('first',$first);
        $this->assign('second',$second);
        $this->assign('third',$third);
        $this->assign('oid',$oid);
        $this->assign('time',$time);
        $this->assign('good',$good);
        $this->display();     
      }
      public function docomment(){
            $id=I('post.goods_id');
            $data= I('post.'); 
            $data['add_time']=time();
            $re=M('comment')->filter('strip_tags')->add($data);
           if($re){            
               $data=M('goods_cate_type')->where(array('goods_id'=>$id))->find();
               $this->assign('goods',$data);
               $this->display("success");
           }
      }
      public function doresponse(){
          $data=I('post.');
          $data['add_time']=time();
          $re=M("comment")->filter("strip_tags")->add($data);
          $arr=array();
          if($re){
              $arr['msg']='回复成功';
              $arr['status']=1;
          }else{
              $arr['msg']='回复失败';
              $arr['status']=0;
          }
          $this->ajaxReturn($arr);
          
      }
      public function delcomment(){
          $re=M('comment')->where(array('id'=>I('get.id')))->delete();
          $arr=array();
          if($re){
              $arr['msg']='删除成功';
              $arr['status']=1;
          }else{
              $arr['msg']='删除失败';
              $arr['status']=0;
          }
          $this->ajaxReturn($arr);
      }
}